# main.py       LAB04

from machine import SPI, Pin
from utime import sleep

spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(14), mosi=Pin(13))
MAX7219_CS = Pin(27, Pin.OUT)
MAX7219_CS.on()

########################################################
def send_data(reg, dta):
	global spi,MAX7219_CS

	MAX7219_CS.off()
	spi.write(bytearray([reg, dta]))
	MAX7219_CS.on()
########################################################
def MAX7219_Init():
	send_data(0x09,0)
	send_data(0x0a,15)
	send_data(0x0b,7)
	send_data(0x0c,1)
	send_data(0x0f,0)
	for i in range(1, 9):
		send_data(i,0)
########################################################

# DOT display pattern
pattn = [[0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00],
		 [0x00, 0x00, 0x3C, 0x24, 0x24, 0x3C, 0x00, 0x00],
		 [0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00],
		 [0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF]]





MAX7219_Init()

while True:
	for i in range (4):
		for j in range (8):
			send_data(j+1,pattn[i][j])
		sleep(0.2)